{{extend 'layout.html'}}

<h2 class="fancy">PyForum - Manage Forums</h2>

{{include 'fadmin/admin_options.html'}}


{{if view_info.has_key('sort_saved'):}}<p class="information">Forums have been re-sorted</p>{{pass}}

{{include 'default/err_check.html'}}

{{if cats:}}
    <form id="sel_cat_form" name="sel_cat_form" method="post">
    <fieldset id="sel_cat_form_fields">
        <p>Select Category:
        <select id="new_cat_id" name="new_cat_id" onchange="location.href=this.value;">
            {{for sel_cat in cats:}}
                <option value="{{=URL(r=request, c='fadmin', f='forums', args=[sel_cat.id])}}"
                        {{if selected_category:}}
                            {{if selected_category.id==sel_cat.id:}}
                                selected="selected"{{pass}}{{pass}}>
                                {{=sel_cat.cat_name}}</option>
            {{pass}}
        </select>
    </fieldset>
    </form>
{{pass}}

{{if selected_category:}}
    <form id="forum_handling_form" method="post">
    <fieldset id="forum_handling_form_fields">
        <input type="hidden" id="form_submitted" name="form_submitted" value="1" />
        <input type="hidden" id="cat_id" name="cat_id" value="{{=selected_category.id}}" />

        {{if cat_forums:}}
            <table class="bordered" style="width: 100%;">
            <thead>
                <tr>
                    <th>Order</th>
                    <th>Title</th>
                    <th>Modded</th>
                    <th>Anon Read</th>
                    <th>Min Roles Add</th>
                    <th>Min Roles Reply</th>
                </tr>
            </thead>
            <tbody>
                {{for idx, this_forum in enumerate(cat_forums):}}
                    <tr class="{{if idx%2:}}shadedark{{else:}}shadelight{{pass}}">
                        <td>
                            <input type="text" id="forum_id_{{=this_forum.id}}" name="forum_id_{{=this_forum.id}}" value="{{=this_forum.forum_sort}}" style="width:50px;" />
                        </td>
                        <td>
                            {{=this_forum.forum_title}}
                            <br /><a href="{{=URL(r=request, c='fadmin', f='edit_forum', args=[this_forum.id])}}"
                                     title="Edit forum properties" class="smallb">Edit forum properties</a>
                            <span class="sep">|</span>
                            <a href="{{=URL(r=request, c='default', f='forum', args=[this_forum.id])}}"
                               title="View/Edit topics in this forum"
                               class="smallb">View/Edit topics in this forum</a>
                        </td>
                        <td>{{=this_forum.moderation_flag}}</td>
                        <td>{{=this_forum.anonymous_viewaccess}}</td>
                        <td>{{=', '.join(this_forum.add_postings_access_roles.split(',')) or 'Anyone'}}</td>
                        <td>{{=', '.join(this_forum.reply_postings_access_roles.split(',')) or 'Anyone'}}</td>
                    </tr>
                {{pass}}
            </tbody>
            </table>
        {{else:}}
            <p class="warning">This category does not have any forums.</p>
        {{pass}}

        <div class="top-separator">
            <input type="submit" id="add_forum" name="add_forum" value="Add New Forum" />
            {{if cat_forums:}}<input type="submit" id="save_sort" name="save_sort" value="Save Sort Order" />{{pass}}
        </div>
    </fieldset>
    </form>
{{else:}}
    <p class="warning">No categories have been created. You must have at least one category to allow forum management.</p>
{{pass}}
